/**
 * CS 307 Red Cross Calendar
 * @author Kevin Barlow
 * @author David Barnes
 * @author Max Cohen
 * @author Yoongu Kang
 * @author Matt Lathrop
 * @author Thomas Maley
 */
package com.cs307.redcross.client;

import java.io.Serializable;
import java.util.Vector;


/**
 * Collection of volunteers. Can add/delete/modify who is in the group.
 */
public class Group implements Serializable {
	private static final long serialVersionUID = 1L; // needed in order to implement Serializable
	private Vector<Person> personList; // stores the Persons that are apart of the group
	private String name;
	private int id;
	private String description;
	private boolean isPublic;
	
	/**
	 * Constructs a blank Group with no Persons added to it
	 */
	public Group() {
		this.personList = new Vector<Person>();
		this.name = "";
		this.id = -1;
	}
	
	public Group(Group group) {
		this.personList = new Vector<Person>(group.personList);
		this.name = group.name;
		this.id = group.id;
	}
	
	/**
	 * Constructs a Group and adds the Persons in the list to it
	 * 
	 * @param a vector of Person objects that will be added to the group
	 */
	public Group(Vector<Person> personList) {
		this.personList = personList;
	}
	
	public Group(String n, Vector<Person> personList, String description, boolean isPublic) {
		this.id = -1;
		this.name = n;
		this.personList = personList;
		this.description = description;
		this.isPublic = isPublic;
	}
	
	@Override
	public String toString() {
		return "Group [personList=" + personList + ", name=" + name + ", id="
				+ id + ", description=" + description + ", isPublic="
				+ isPublic + "]";
	}
	
	/**
	 * 
	 */
	public void addPersonToGroup(Person person) {
		if (personList == null) {
			//TODO: probably throw an exception but for now we will just initialize it
			personList = new Vector<Person>();
		}
		personList.add(person);
	}
	
	public boolean removePersonFromGroup(Person person){
		if(personList==null) return false;
		if(personList.isEmpty()) return false;
		
		Person remove = null;
		for (Person p : personList) {
			if (p == null)
				continue;
			
			if (p.getID() == person.getID()) {
				remove = p;
				break;
			}
		}
		if (remove != null) {
			personList.remove(remove);
			return true;
		}
		return false;
	}
	
	
	// getters *******************************************************

	/**
	 * @return a vector of all Persons that are apart of the group
	 */
	public Vector<Person> getPersonList() {
		return this.personList;
	}
	
	public String getName() {
		return name;
	}
	
	public int getID()
	{
		return this.id;
	}
	
	// setters *******************************************************
	public void setId(int id) {
		this.id = id;
	}
	/**
	 * @param a Vector<Person> that stores the new list of persons for the group
	 */
	public void setPersonList(Vector<Person> personList) {
		this.personList = personList;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return description;
	}

	public void setPublic(boolean isPublic) {
		this.isPublic = isPublic;
	}

	public boolean isPublic() {
		return isPublic;
	}
}
